<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            height: 100vh;
            background: #e7e7e7 url("./image/mr.jpg") center no-repeat fixed;
            background-size: cover;
            backdrop-filter: blur(5px);
            /*界面模糊 */
        }

        /* 设置方格 */
        .container {
            background-color: #e7e7e7;
            border-radius: 0.7rem;
            box-shadow:
                0 0.9rem 1.7em rgba(0, 0, 0, 0.25),
                0 0.74m 0.7em rgba(0, 0, 0, 0.22);
            height: 420px;
            max-width: 750px;
            overflow: hidden;
            position: relative;
            width: 100%;
        }

        /* 方格居中 */
        body {
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .container-form {
            height: 100%;
            position: absolute;
            top: 0;
            transition: all 0.6s ease-in-out;
        }

        .container-signin {
            left: 0;
            width: 50%;
            z-index: 2;
        }

        .container-signup {
            left: 0;
            opacity: 0;
            width: 50%;
            z-index: 1;
        }

        .form {
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            padding: 0 3rem;
            height: 100%;
            text-align: center;
            background-color: #e7e7e7;
        }

        .form-title {
            font-weight: 300;
            margin: 0;
            margin-bottom: 1.25rem;
        }

        .link {
            color: #333;
            font-size: 0.9rem;
            margin: 1.5rem 0;
            text-decoration: none;
        }

        .input {
            width: 100%;
            background-color: #fff;
            padding: 0.9rem 0.9rem;
            margin: 0.5rem 0;
            border: none;
            outline: none;
        }

        .btn {
            background-color: #f25d8e;
            box-shadow: 0 4px 4px rgba(225, 112, 159, 3);
            border-radius: 5px;
            color: #e7e7e7;
            border: none;
            cursor: pointer;
            font-size: 0.8rem;
            font-weight: bold;
            letter-spacing: 0.1rem;
            padding: 0.9rem 4rem;
            text-transform: uppercase;
            transition: transform 80ms ease-in;
        }

        .form>.btn {
            margin-top: 1.5rem;
        }

        .btn:active {
            transform: scale(0.95);
        }

        /* 叠加层部分 */
        .container-overlay {
            height: 100%;
            left: 50%;
            overflow: hidden;
            position: absolute;
            top: 0;
            transition: transform 0.6s ease-in-out;
            width: 50%;
            z-index: 100;
        }

        .overlay {
            width: 200%;
            height: 100%;
            position: relative;
            left: -100%;
            background: url("./image/mr.jpg") no-repeat center fixed;
            background-size: cover;
            transition: transform 0.6s ease-in-out;
            transform: translateX(0);
        }

        .overlay-panel {
            height: 100%;
            width: 50%;
            position: absolute;
            top: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            transform: translateX(0);
            transition: transform 0.6s ease-in-out;
        }

        .overlay-left {
            transform: translateX(-20%);
        }

        .overlay-right {
            right: 0;
            transform: translateX(0);
        }

        .panel-active .overlay-left {
            transform: translateX(0);
        }

        .panel-active .container-overlay {
            transform: translateX(-100%);
        }

        .panel-active .overlay {
            transform: translateX(50%);
        }

        .panel-active .container-signin {
            transform: translateX(100%);
        }

        .panel-active .container-signup {
            opacity: 1;
            z-index: 5;
            transform: translateX(100%);
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 注册 -->
        <div class="container-form container-signup">
            <!-- 注意表单的提交位置和提交方式 -->
            <form action="http://47.115.227.93:8080/register" class="form" id="form1" method="post">
                <h2 class="form-title">注册账号</h2>
                <!-- 注意表单要有name,不然不会提交 -->
                <input type="text" placeholder="User" name="User" class="input">
                <input type="email" placeholder="Email" name="Email" class="input" id="Email">
                <input type="password" placeholder="Password" name="Password" class="input">
                <input type="submit" class="btn" id="btn"></input>
            </form>
        </div>

        <!-- 登录 -->
        <div class="container-form container-signin">
            <form action="http://47.115.227.93:8080/checked" class="form" id="form2" method="post">
                <h2 class="form-title">欢迎登录</h2>
                <input type="email" placeholder="Email" name="Email" class="input" id="email">
                <input type="password" placeholder="Password" name="Password" class="input">
                <a href="#" class="link">忘记密码</a>
                <input type="submit" class="btn"></input>
            </form>
        </div>

        <!-- 叠加层部分 -->
        <div class=container-overlay>
            <div class="overlay">
                <div class="overlay-panel overlay-left">
                    <button class="btn" id="signIn">已有账号,点击注册</button>
                </div>
                <div class="overlay-panel overlay-right">
                    <button class="btn" id="signUp">没有账号,立即注册</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    const signInBtn
        = document.querySelector('#signIn')
    const signUnBtn
        = document.querySelector('#signUp')
    const container
        = document.querySelector('.container')

    signInBtn.addEventListener("click", () => {
        container.classList.remove("panel-active")
    })
    signUnBtn.addEventListener("click", () => {
        container.classList.add("panel-active")
    })

    //检测cookie
    checkCookie();//cookie存在,直接跳转

    //获取url
    let url = window.location.href;
    if (url.lastIndexOf("?") != -1) {
        url = decodeURI(url);//解码
        //找到问号
        let pos = url.lastIndexOf("?");
        //切割后面的内容
        let message = url.slice(pos + 1);
        //&分隔符会被识别为%26
        if (message.lastIndexOf('%26') == -1)//不是登录成功,是密码错误或者账号没有注册
        {
            //重定向,防止持续输出
            window.location.href = "http://47.115.227.93:8080/LogIn.html";
            //输出
            alert(message);
        }
        else {
            let splitpos = message.lastIndexOf('%26');
            let name = message.slice(0, splitpos);//获取用户名
            let value = name + "," + message.slice(splitpos + 3);//获取值
            setCookie("username", value, 1);//有效期一天
            //重定向,防止持续输出
            window.location.href = "http://47.115.227.93:8080/HomePage.html";
            //输出
            alert("登录成功");
        }
    }

    //设置cookie
    function setCookie(cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        var expires = "expires=" + d.toGMTString();
        document.cookie = cname + "=" + cvalue + "; " + expires;
    }

    //获取cookie
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
        return "";
    }

    //检测cookie
    function checkCookie() {
        var username = getCookie("username");
        if (username != "") {
            let pos = username.indexOf('%');
            let message = username.slice(0, pos);
            alert("你先前已经登录成功");
            window.location.href = "http://47.115.227.93:8080/HomePage.html";
        }
    }

</script>

</html>